/* @(#)CategoryDown.java   
 *
 * Project: GS-1
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-7-7     新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.autotask;

import java.io.DataInputStream;

import java.net.URL;

import system.LoginContext;
import system.base.User;
import system.base.Warehouse;
import system.data.UserBase;

import com.hitrust.gs.business.GSFileUploadProcessor;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.GSSystemConfigurator;
import com.hitrust.gs.lib.db.GSBaseDAO;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;

import framework.core.Conditions;
import framework.core.ConstDefine;
import framework.core.DBConnection;

/**
 * 
 */
public class CategoryDown {
    
    
    public void doDown(){
        String tResult="";
        DataInputStream dis = null;
        
        try {
            GSLogWriter.info ("Begin to Down Category Data... ");
            String tDay=DateUtil.getNextUpDay(-1);
            //文件下载
            String Name="/Category_"+tDay+".xls";
            URL url = new URL(GSSystemConfigurator.getParam("gs.down.schema")+"://"+GSSystemConfigurator.getParam("gs.down.host")+":"+GSSystemConfigurator.getParam("gs.down.port")+"/"+GSSystemConfigurator.getParam("gs.down.fullpath")+Name);
     
            dis = new DataInputStream(url.openStream());
            
            
            try{
                //导入商户信息
                LoginContext loginContext = new LoginContext();
                User user=new User();
                user.setId(ConstDefine.T_USER_SUPERADMIN_ID);
                user.setName(ConstDefine.T_USER_SUPERADMIN_CODE);
                loginContext.setUser(user);
                tResult=GSFileUploadProcessor.batchImportManufactureCategory(dis,"",loginContext);
            }catch(GSException e){            
                GSLogWriter.error(e.getMessage());            
            }
            //从返回的值中取得失败和成功的数据
            String tSuccess= tResult.split("-")[0];
            String tFail= tResult.split("-")[1];
            String tOutputPath = tResult.split("-")[2];

            if(Integer.parseInt(tFail)>0){
                GSLogWriter.error("Fail down Category output path: " + tOutputPath);
                GSLogWriter.error("Fail import Category count: " + tFail);
            }
            GSLogWriter.info("Success import Category count: " + tSuccess);
        }
        catch (Exception ex) {
            GSLogWriter.error("下载产品类别时出错!");
            GSLogWriter.error(ex.getMessage());
        }       
        
    }

    /**{
     * 
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    }

}
